//
//  TTSizeGuideViewController.m
//  TaoTuo
//
//  Created by admin on 2020/1/3.
//  Copyright © 2020 admin. All rights reserved.
//

#import "TTSizeGuideViewController.h"
#import <JXPagingView/JXPagerView.h>
#import <JXCategoryView.h>
#import "TTSizeGuideView.h"
#import "AppDelegate.h"

#define titleViewH 34

@interface TTSizeGuideViewController ()<JXCategoryViewDelegate, JXCategoryListContainerViewDelegate, JXCategoryListContentViewDelegate>
{
    TTSizeGuideView *guideView1;
    TTSizeGuideView *guideView2;
}

@property (nonatomic, strong) JXCategoryTitleView *categoryTitleView;
@property (nonatomic, strong) JXCategoryListContainerView *listContainerView;
@property (nonatomic, strong) NSArray *titles;
@property (nonatomic, strong) NSArray *contents;

@property (nonatomic, strong) NSArray *webViewsArray;

@end

@implementation TTSizeGuideViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"尺寸指南";
    
    self.contents = @[@"1.html", @"2.html"];
    
    [self setupSubviews];
    
}


- (void)setupSubviews
{
    self.titles = @[@"戒指篇", @"手镯篇"];
    self.categoryTitleView = [[JXCategoryTitleView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, titleViewH)];
    self.categoryTitleView.delegate = self;
    self.categoryTitleView.titles = self.titles;
    [self.view addSubview:self.categoryTitleView];
//    self.categoryTitleView.contentEdgeInsetLeft = 20;        // 左边距
//    self.categoryTitleView.contentEdgeInsetRight = 20;       // 右边距
    self.categoryTitleView.titleSelectedColor = UIColorHex(333333);
    self.categoryTitleView.titleColor = UIColorHex(333333);
    self.categoryTitleView.titleLabelZoomEnabled = NO;
    [self.view addSubview:self.categoryTitleView];
    
    JXCategoryIndicatorLineView *lineView = [[JXCategoryIndicatorLineView alloc] init];
    lineView.indicatorColor = UIColorHex(9B71FF);
    lineView.indicatorHeight = 8;
    lineView.verticalMargin = 6;
    lineView.indicatorCornerRadius = 4;
    lineView.lineStyle = JXCategoryIndicatorLineStyle_Lengthen;
    self.categoryTitleView.indicators = @[lineView];
    
    
    _listContainerView = [[JXCategoryListContainerView alloc] initWithDelegate:self];
    _listContainerView.frame = CGRectMake(0, titleViewH, SCREEN_WIDTH, self.view.height - StatusBarAndNavBar_Height - Tabbar_Bottom_height - titleViewH);
    [self.view addSubview:_listContainerView];
    
    self.categoryTitleView.contentScrollView = self.listContainerView.scrollView;
    
    if (self.webViewsArray.count == 0) {
        guideView1 = [[TTSizeGuideView alloc] initWithFrame:_listContainerView.bounds];
        guideView2 = [[TTSizeGuideView alloc] initWithFrame:_listContainerView.bounds];
        self.webViewsArray = @[guideView1, guideView2];
        
    }
    
}



#pragma mark - JXCategoryViewDelegate
- (void)categoryView:(JXCategoryBaseView *)categoryView didScrollSelectedItemAtIndex:(NSInteger)index {
    //    NSLog(@"%@", NSStringFromSelector(_cmd));
}

- (void)categoryView:(JXCategoryBaseView *)categoryView didClickSelectedItemAtIndex:(NSInteger)index {
    
    [self.listContainerView didClickSelectedItemAtIndex:index];
}

- (void)categoryView:(JXCategoryBaseView *)categoryView scrollingFromLeftIndex:(NSInteger)leftIndex toRightIndex:(NSInteger)rightIndex ratio:(CGFloat)ratio {
    [self.listContainerView scrollingFromLeftIndex:leftIndex toRightIndex:rightIndex ratio:ratio selectedIndex:categoryView.selectedIndex];
}

#pragma mark - JXCategoryListContainerViewDelegate

- (id<JXCategoryListContentViewDelegate>)listContainerView:(JXCategoryListContainerView *)listContainerView initListForIndex:(NSInteger)index {
    
    NSString *path = [[NSBundle mainBundle] pathForResource:self.contents[index] ofType:nil];
    NSURL *url = [NSURL fileURLWithPath:path];
    
    TTSizeGuideView *webView = self.webViewsArray[index];
    [webView setupUrl:url];
    
    return webView;
    
}

- (NSInteger)numberOfListsInlistContainerView:(JXCategoryListContainerView *)listContainerView {
    return self.titles.count;
}


- (UIView *)listView
{
    return self.view;
}




@end
